package ute.mvc.dto;

import java.util.ArrayList;
import java.util.List;

public class TestUtil {

	public static TestDTO formatQuestionDTO(TestDTO test){
		for(int i = 0; i < test.getListPart().size(); i++){
			for(int j = 0; j < test.getListPart().get(i).getListQuestion().size(); j++){
				QuestionDTO dto = test.getListPart().get(i).getListQuestion().get(j);
				dto.setAnswers(parseAnswer(dto.getAnswer(), dto.getType()));
			}
		}
		
		return test;
	}
	
	private static List<String> parseAnswer(String answer, int type) {

		List<String> answers = new ArrayList<String>();
		if (type == 1) {
			return answers; // True false, don't use answer
		}
		String[] str = answer.split(";");
		for (int i = 0; i < str.length; i++) {
			answers.add(str[i].substring(2, str[i].length()));
		}
		return answers;
	}
}
